//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2021 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto/tree/main/CodeGenerator. DO NOT EDIT.

import SotoCore

/// Error enum for CloudWatch
public struct CloudWatchErrorType: AWSErrorType {
    enum Code: String {
        case concurrentModificationException = "ConcurrentModificationException"
        case dashboardInvalidInputError = "InvalidParameterInput"
        case internalServiceFault = "InternalServiceError"
        case invalidFormatFault = "InvalidFormat"
        case invalidNextToken = "InvalidNextToken"
        case invalidParameterCombinationException = "InvalidParameterCombination"
        case invalidParameterValueException = "InvalidParameterValue"
        case limitExceededException = "LimitExceededException"
        case limitExceededFault = "LimitExceeded"
        case missingRequiredParameterException = "MissingParameter"
        case resourceNotFound = "ResourceNotFound"
        case resourceNotFoundException = "ResourceNotFoundException"
    }

    private let error: Code
    public let context: AWSErrorContext?

    /// initialize CloudWatch
    public init?(errorCode: String, context: AWSErrorContext) {
        guard let error = Code(rawValue: errorCode) else { return nil }
        self.error = error
        self.context = context
    }

    internal init(_ error: Code) {
        self.error = error
        self.context = nil
    }

    /// return error code string
    public var errorCode: String { self.error.rawValue }

    /// More than one process tried to modify a resource at the same time.
    public static var concurrentModificationException: Self { .init(.concurrentModificationException) }
    /// Some part of the dashboard data is invalid.
    public static var dashboardInvalidInputError: Self { .init(.dashboardInvalidInputError) }
    /// Request processing has failed due to some unknown error, exception, or failure.
    public static var internalServiceFault: Self { .init(.internalServiceFault) }
    /// Data was not syntactically valid JSON.
    public static var invalidFormatFault: Self { .init(.invalidFormatFault) }
    /// The next token specified is invalid.
    public static var invalidNextToken: Self { .init(.invalidNextToken) }
    /// Parameters were used together that cannot be used together.
    public static var invalidParameterCombinationException: Self { .init(.invalidParameterCombinationException) }
    /// The value of an input parameter is bad or out-of-range.
    public static var invalidParameterValueException: Self { .init(.invalidParameterValueException) }
    /// The operation exceeded one or more limits.
    public static var limitExceededException: Self { .init(.limitExceededException) }
    /// The quota for alarms for this customer has already been reached.
    public static var limitExceededFault: Self { .init(.limitExceededFault) }
    /// An input parameter that is required is missing.
    public static var missingRequiredParameterException: Self { .init(.missingRequiredParameterException) }
    /// The named resource does not exist.
    public static var resourceNotFound: Self { .init(.resourceNotFound) }
    /// The named resource does not exist.
    public static var resourceNotFoundException: Self { .init(.resourceNotFoundException) }
}

extension CloudWatchErrorType: Equatable {
    public static func == (lhs: CloudWatchErrorType, rhs: CloudWatchErrorType) -> Bool {
        lhs.error == rhs.error
    }
}

extension CloudWatchErrorType: CustomStringConvertible {
    public var description: String {
        return "\(self.error.rawValue): \(self.message ?? "")"
    }
}
